<template>
  <div class="eventLevel">
    <CommonBtn label-name="年份设定管理" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+item.value}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions" @dbClick="openItem"></CommonList>
    <CommonEdit v-if="button && (button.event=='add()' || button.event=='edit()' || button.event=='detail()')"
                :outBtn="button" :props="add"
                :original-data="row" :add-url="$api.API_ADDMDMYEAR" :edit-url="$api.API_UPDMDMYEAR"
                @editBack="editBack"></CommonEdit>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_EXPORTMDMYEAR" :conditions="conditions"></CommonExport>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList";
    import CommonBtn from "../../common/CommonBtn";
    import CommonEdit from "../../common/CommonEdit";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";

    export default {
        name:'dataYear',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.ADD,
                    this.$config.BTNS.EDIT,
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'year',
                        label:'年份',
                        search:true,
                        type:'text',
                    },
                    {
                        prop:'active',
                        label:'是否激活',
                        customSet(value) {
                            /* if (value && value == '1') {
                                return 'true'
                            }
                            return 'false' */
                            return value
                        },
                    },
                    {
                        prop:'createUserName',
                        label:'创建者'
                    },
                    {
                        prop:'modifyUserName',
                        label:'最后修改者'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    }
                ],
                listUrl: this.$api.API_SELECTMDMYEAR,
                button:null,
                add:{
                    label:'年份设定',
                    addItems:[
                        {name:'年份',prop:'year',type:'text'},
                        {name:'是否激活',prop:'active',type:'checkbox',trueLabel:1,falseLabel:0},
                        {name:'备注',prop:'memo',type:'textarea'}
                    ],
                },
                conditions:[],
                row:{}
            }
        },
        methods:{
            onButtonClick(item) {
                if (item.event == 'edit()' || item.event == 'detail()') {
                    if (!this.row || JSON.stringify(this.row) == '{}') {
                        this.$message.error("请选择一行数据")
                        return
                    }
                }
                if (item.event == 'add()') {
                    this.row = {}
                }

                this.button = item
            },
            editBack(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
                this.$delete (this.row,'createTime')
                this.$delete (this.row,'modifyTime')
            },
            conditionChange(conditions) {
                this.$refs.list.search()
            },
            close(item) {
                this.button = item
            },
            openItem(item) {
                this.button = this.$config.BTNS.DETAIL
            },
        },
        components:{CommonExport,SearchPopUp, CommonList,CommonBtn,CommonEdit,},
    }
</script>
